package com.ruoyi.web.controller.devops;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.devops.domain.DevOpsAttrPara;
import com.ruoyi.devops.service.IDevOpsAttrParaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参数管理Controller
 * 
 * @author ruoyi
 * @date 2023-01-26
 */
@Controller
@RequestMapping("/devops/para")
public class DevOpsAttrParaController extends BaseController
{
    private String prefix = "devops/para";

    @Autowired
    private IDevOpsAttrParaService devOpsAttrParaService;

    @RequiresPermissions("devops:para:view")
    @GetMapping()
    public String para()
    {
        return prefix + "/para";
    }

    /**
     * 查询参数管理列表
     */
    @RequiresPermissions("devops:para:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DevOpsAttrPara devOpsAttrPara)
    {
        startPage();
        List<DevOpsAttrPara> list = devOpsAttrParaService.selectDevOpsAttrParaList(devOpsAttrPara);
        return getDataTable(list);
    }

    /**
     * 导出参数管理列表
     */
    @RequiresPermissions("devops:para:export")
    @Log(title = "参数管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DevOpsAttrPara devOpsAttrPara)
    {
        List<DevOpsAttrPara> list = devOpsAttrParaService.selectDevOpsAttrParaList(devOpsAttrPara);
        ExcelUtil<DevOpsAttrPara> util = new ExcelUtil<DevOpsAttrPara>(DevOpsAttrPara.class);
        return util.exportExcel(list, "参数管理数据");
    }

    /**
     * 新增参数管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存参数管理
     */
    @RequiresPermissions("devops:para:add")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DevOpsAttrPara devOpsAttrPara)
    {
        return toAjax(devOpsAttrParaService.insertDevOpsAttrPara(devOpsAttrPara));
    }

    /**
     * 修改参数管理
     */
    @RequiresPermissions("devops:para:edit")
    @GetMapping("/edit/{attrkey}")
    public String edit(@PathVariable("attrkey") String attrkey, ModelMap mmap)
    {
        DevOpsAttrPara devOpsAttrPara = devOpsAttrParaService.selectDevOpsAttrParaByAttrkey(attrkey);
        mmap.put("devOpsAttrPara", devOpsAttrPara);
        return prefix + "/edit";
    }

    /**
     * 修改保存参数管理
     */
    @RequiresPermissions("devops:para:edit")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DevOpsAttrPara devOpsAttrPara)
    {
        return toAjax(devOpsAttrParaService.updateDevOpsAttrPara(devOpsAttrPara));
    }

    /**
     * 删除参数管理
     */
    @RequiresPermissions("devops:para:remove")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(devOpsAttrParaService.deleteDevOpsAttrParaByAttrkeys(ids));
    }
}
